package net.lab1024.sa.admin.module.business.projectLists.service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import net.lab1024.sa.admin.module.business.projectLists.dao.ProjectListsDao;
import net.lab1024.sa.admin.module.business.projectLists.domain.entity.ProjectListsEntity;
import net.lab1024.sa.admin.module.business.projectLists.domain.form.ProjectListsAddForm;
import net.lab1024.sa.admin.module.business.projectLists.domain.form.ProjectListsQueryForm;
import net.lab1024.sa.admin.module.business.projectLists.domain.form.ProjectListsUpdateForm;
import net.lab1024.sa.admin.module.business.projectLists.domain.vo.ProjectListsVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * 企业列表 Service
 *
 * @Author 1
 * @Date 2025-06-30 10:10:25
 * @Copyright 1
 */

@Service
public class ProjectListsService {

    @Resource
    private ProjectListsDao projectListsDao;

    /**
     * 分页查询
     */
    public PageResult<ProjectListsVO> queryPage(ProjectListsQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<ProjectListsVO> list = projectListsDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(ProjectListsAddForm addForm) {
        ProjectListsEntity projectListsEntity = SmartBeanUtil.copy(addForm, ProjectListsEntity.class);
        UUID uuid = UUID.randomUUID();
        projectListsEntity.setUuid(uuid.toString());
        projectListsEntity.setCreatedAt(new Date());
        projectListsEntity.setUpdatedAt(new Date());
        projectListsDao.insert(projectListsEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(ProjectListsUpdateForm updateForm) {
        ProjectListsEntity projectListsEntity = SmartBeanUtil.copy(updateForm, ProjectListsEntity.class);
        projectListsDao.updateById(projectListsEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        projectListsDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        projectListsDao.deleteById(id);
        return ResponseDTO.ok();
    }

    /**
     *
     * @param uuid
     * @return
     */
    public ResponseDTO<ProjectListsVO> getByUuid(String uuid) {
        return ResponseDTO.ok(projectListsDao.getByUuid(uuid));
    }
}
